﻿Shader "Dan/2D/Fire2D"
{
    Properties
    {
        
        _MainTex ("Texture", 2D) = "white" {}
        [Header(FireShape)]
        _FlowSpeed("Flow Speed",Float) =5
        _ScaleX("ScaleX",Float) =5
        _ScaleY("ScaleY",Float) =5
        _VerticalMask("Vertical Mask",Range(0,5)) =1
        _HorizontalMask("Horizontal Mask",Range(0,1)) =1 
        _Blur("Blur",Range(0,0.9)) =0.2
        _Size("Size",Range(0,0.9))=0.5
        _DistortVal("DistortVal",Range(0.1,2)) =1


        [Header(ColorBlend)]
        [Enum(Lerp,0,Blend,1,CosBlend,2)]
        _BlendType("BlendType",Int)=1

        [Header(BlendType)]
        _BlendColor1("Blend Color1", Color) =(1,1,1,1)
        _BlendColorMid("Blend Color Mid", Color) =(1,1,1,1)
        _BlendColor2("Blend Color2", Color) =(1,1,1,1)
        _BlendColorOffset("Blend ColorOffset", Range(0.05,0.95)) =0.7

        [Header(LerpType)]
        _LerpColor1("Lerp Color1", Color) =(1,1,1,1)
        _LerpColor2("Lerp Color2", Color) =(1,1,1,1)

        [Header(CosBlendColorType)]
        _CosBlendColor1("CosBlendColor1", Color) =(1,1,1,1)
        _CosBlendColor2("CosBlendColor2", Color) =(1,1,1,1)
        _CosBlendColor3("CosBlendColor3", Vector) =(1,1,1,1)
        _CosBlendColor4("CosBlendColor4", Vector) =(1,1,1,1)

    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue" ="Transparent" }
        LOD 100

        Pass
        {
            Blend SrcColor One 
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"
            #include "../ShaderLibs/Hash.cginc"
            #include "../ShaderLibs/Feature.cginc"
            #include "../ShaderLibs/ColorBlend.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            
            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                
                return o;
            }

            
            float _FlowSpeed;
            float _ScaleX;
            float _ScaleY;
            float _VerticalMask;
            float _HorizontalMask;
            float _Blur;
            float _Size;
            float _DistortVal;
            
            float4 _BlendColor1;
            float4 _BlendColorMid;
            float4 _BlendColor2;
            float _BlendColorOffset;

        
            float4 _LerpColor1;
            float4 _LerpColor2;

        
            float4 _CosBlendColor1;
            float4 _CosBlendColor2;
            float3 _CosBlendColor3;
            float3 _CosBlendColor4;

            int _BlendType;

            

            fixed4 frag (v2f i) : SV_Target
            {
                float4 finalcolor = 0;
                float2 uv =i.uv;
                
                float2 scale =float2(_ScaleX,_ScaleY);
                float speed =_Time.y*_FlowSpeed;
                float2 maskXY = float2(_HorizontalMask,_VerticalMask);
                float2 ssMinMax = float2(_Size,_Size+_Blur);
                
                
                float fire= DrawFire(uv,scale,speed,_DistortVal,maskXY,ssMinMax);

                if (_BlendType==0) finalcolor =LerpColor(fire,_LerpColor1,_LerpColor2);
                if (_BlendType==1) finalcolor =BlendColor(fire,_BlendColor1,_BlendColorMid,_BlendColor2,_BlendColorOffset);
                if (_BlendType==2) finalcolor.rgb = CosBlendColor(fire,_CosBlendColor1,_CosBlendColor2,_CosBlendColor3,_CosBlendColor4) ;
                return finalcolor*fire;  
            }
            ENDCG
        }
    }
}
